<template>
  <div class="model-card"
       ref="modelCard"
       @mouseenter="handleMouseEnter"
       @mouseleave="handleMouseLeave"
  >
    <div class="img-wrapper">
      <img class="model-preview-img" :src="cardData.previewImgUrl || '#'" />
      <div class="card-overlay card-overlay-hidden" ref="overlay">
<!--        <el-button type="primary" @click="handleEdit">修改</el-button>-->
        <el-button type="primary" @click="handleApply">应用此模板</el-button>
<!--        <el-button type="default" @click="handleCopy">复制</el-button>-->
<!--        <el-button type="danger" @click="handleDelete">删除</el-button>-->
      </div>
    </div>
    <div class="img-title">
      {{cardData.name}}
    </div>

  </div>
</template>

<script lang="ts" setup>
const props = defineProps<{
  cardData: any,
  index: string | number
}>()

const emits = defineEmits(['edit', 'copy', 'delete', 'apply'])
const modelCard = ref<HTMLElement>()
const overlay = ref<HTMLElement>()

const handleMouseEnter = (e: MouseEvent) => {
  overlay.value?.classList.remove('card-overlay-hidden')
}

const handleMouseLeave = (e: MouseEvent) => {
  overlay.value?.classList.add('card-overlay-hidden')
}

const handleApply = () => {
  emits('apply', props.cardData)
}

// const handleEdit = () => {
//   emits('edit', props.cardData)
// }
//
// const handleDelete = () => {
//   emits('delete', props.cardData)
// }
//
// const handleCopy = () => {
//   emits('copy', props.cardData)
// }

</script>

<style scoped lang="scss">

.model-card {
  background: white;
  float: left;
  margin-right: 20px;
  margin-bottom: 20px;

  .img-wrapper {
    width: 200px;
    height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 3px 0 var(--el-color-primary-light-5);
    border-radius: 5px;
    position: relative;

    .model-preview-img {
      max-width: 200px;
      max-height: 200px;
    }
  }

  .img-title {
    width: 200px;
    margin-top: 10px;
    font-size: 14px;
    line-height: 14px;
    height: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: keep-all;
    white-space: nowrap;
  }

}

.card-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;

  :deep(.el-button) {
    margin-bottom: 10px;

    +.el-button {
      margin-left: 0;
    }
  }
}

.card-overlay-hidden {
  display: none;
}
</style>
